package co.fitstart.admin.entity.content;


import java.util.Map;

import com.demo2do.core.persistence.support.Filter;
import com.demo2do.core.persistence.support.Order;
import com.demo2do.core.persistence.support.QueryBuilder;

import co.fitstart.entity.coupon.Type;

public class CouponTemplateSearch implements QueryBuilder {
    
    /** 模版名称 */
    private String name;
    
    /** 模版类别 */
    private Type type;
    
    private Order order;
    
    private Filter filter;
    
    /**
     * default constructor
     */
    public CouponTemplateSearch() {
        order = new Order("createTime", "DESC");
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public Filter getPreparedFilter(boolean refresh) {
        if(filter == null || refresh) {

            filter = new Filter().addLike("name", name)
                                 .addEquals("type", type)
                                 .addEquals("disabled", false);

        }

        return filter;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        return "FROM CouponTemplate " + getPreparedFilter(false).getWhereSentence() + order.getSentence();
    }
    

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).getParameters();
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public Order getOrder() {
        return order;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the type
     */
    public Type getType() {
        return type;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param type the type to set
     */
    public void setType(Type type) {
        this.type = type;
    }
}
